home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Interfaces / UniversalInterfaces 1.0 / CIncludes / stdio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-18  |  6.4 KB  |  283 lines  |  [TEXT/MPS ]

  1. /************************************************************
  2.  
  3.     StdIO.h
  4.     Input / output
  5.     
  6.     Copyright © Apple Computer,Inc.  1985-1991, 1993-1994.
  7.  
  8.     Copyright American Telephone & Telegraph
  9.     Used with permission, Apple Computer Inc. (1985)
  10.     All Rights Reserved.
  11.  
  12. ************************************************************/
  13.  
  14.  
  15. #ifndef __STDIO__
  16. #define __STDIO__
  17.  
  18. #ifndef NULL
  19. #define NULL 0
  20. #endif
  21.  
  22. #ifndef __size_t__
  23. #define __size_t__
  24. typedef unsigned int size_t;
  25. #endif
  26.  
  27. #ifndef __va_list__
  28. #define __va_list__
  29. typedef char *va_list;
  30. #endif
  31.  
  32.  
  33. /*
  34.  *    The basic data structure for a stream is the FILE.
  35.  */
  36.  
  37. #ifdef powerc
  38. #pragma options align=power
  39. #endif
  40. struct FILE {
  41.     int             _cnt;
  42.     unsigned char    *_ptr;
  43.     unsigned char    *_base;
  44.     unsigned char    *_end;
  45.     unsigned short    _size;
  46.     unsigned short    _flag;
  47.     unsigned short    _file;
  48. };
  49. #ifdef powerc
  50. #pragma options align=reset
  51. #endif
  52. typedef struct FILE FILE;
  53.  
  54.  
  55. /*
  56.  *    fpos_t is a type that can express any position in a file.  A file's
  57.  *    end-of-file marker has type fpos_t.
  58.  */
  59.  
  60. typedef long fpos_t;
  61.  
  62.  
  63. /*
  64.  *    These macros give the meanings of bits in a FILE's _flag.  setvbuf() takes
  65.  *    one of _IOFBF, _IOLBF, or _IONBF as its third argument.
  66.  */
  67.  
  68. #define _IOFBF        0            /* Pseudo-flag, default buffering style */
  69. #define _IOREAD     (1<<0)        /* Current mode is for reading */
  70. #define _IOWRT        (1<<1)        /* Current mode is for writing */
  71. #define _IONBF        (1<<2)        /* no buffering */
  72. #define _IOMYBUF    (1<<3)        /* buffer was allocated by stdio */
  73. #define _IOEOF        (1<<4)
  74. #define _IOERR        (1<<5)
  75. #define _IOLBF        (1<<6)        /* fflush(iop) when a \n is written */
  76. #define _IORW        (1<<7)        /* Enable read/write access */
  77. #define _IOSYNC        (1<<8)        /* Input triggers fflush() to output fp's */
  78. #define _IOBINARY    (1<<9)        /* Binary stream */
  79. #define _IOBACK        (1<<14)        /* Result of "ungetc() is in the buffer */ 
  80.  
  81.  
  82. /*
  83.  *    Default file buffer sizes used by setbuf() and setvbuf().
  84.  */
  85.  
  86. #define BUFSIZ    1024            /* default file buffer size */
  87. #define _LBFSIZ  254            /* Line buffer size */
  88.  
  89.  
  90. /*
  91.  *    The standard end-of-file indicator.
  92.  */
  93.  
  94. #define EOF        (-1)
  95.  
  96.  
  97. /*
  98.  *    L_tmpnam is the size of char array long enough to hold a temporary file name
  99.  *    generated by tmpnam(), including the trailing null byte.  The name is in the
  100.  *    form tmp.AAAXXXXXX, where AAA is a sequence of lower case letters ("aaa", "baa",
  101.  *    ... "zzz" on successive calls), and XXXXXX is a lower case letter followed by a sequence
  102.  *    of digits, all determined at runtime.
  103.  *    TMP_MAX is the number of distinct file names that tmpnam() can generate.
  104.  */
  105.  
  106. #define L_tmpnam    14
  107. #define TMP_MAX        17576
  108.  
  109.  
  110. /*
  111.  *    The minimum number of files that a program is guaranteed to be able to have
  112.  *    open simultaneously (including the pre-opened stdin, stdout, and stderr).
  113.  *    The numbers are listed in Inside Macintosh, page IV-178, as:
  114.  *    64K ROM, 128K Macintosh        12 files
  115.  *    64K ROM, 512K Macintosh        40 files
  116.  *    128K ROM                    40 files per volume
  117.  */
  118.  
  119. #define FOPEN_MAX    12
  120.  
  121.  
  122. /*
  123.  *    Maximum length of a file name, including a trailing zero byte.
  124.  */
  125.  
  126. #define FILENAME_MAX    32
  127.  
  128.  
  129. /*
  130.  *    For use by fseek():
  131.  */
  132.  
  133. #ifndef __FCNTL__            /* these defns exactly paralled in FCntl.h for lseek() */
  134.  
  135. #define SEEK_CUR    1
  136. #define SEEK_END    2
  137. #define SEEK_SET    0
  138. #endif
  139.  
  140.  
  141. /*
  142.  *    The standard predefined streams.
  143.  */
  144.  
  145. #define stdin        (&_iob[0])
  146. #define stdout        (&_iob[1])
  147. #define stderr        (&_iob[2])
  148.  
  149.  
  150. #ifdef __cplusplus
  151. extern "C" {
  152. #endif
  153.  
  154. /*
  155.  *    Operations on files
  156.  */
  157.  
  158. int remove(const char *filename);
  159. int rename(const char *oldname, const char *newname);
  160. FILE *tmpfile(void);
  161. char *tmpnam(char *s);
  162.  
  163.  
  164. /*
  165.  *    File access functions
  166.  */
  167.  
  168. int fclose(FILE *stream);
  169. int fflush(FILE *stream);
  170. FILE *fopen(const char *filename, const char *mode);
  171. FILE *freopen(const char *filename, const char *mode, FILE *stream);
  172. void setbuf(FILE *stream, char *buf);
  173. int setvbuf(FILE *stream, char *buf, int mode, size_t size);
  174.  
  175.  
  176. /*
  177.  *    Formatted input/output functions
  178.  */
  179.  
  180. int fprintf(FILE *stream, const char *format, ...);
  181. int fscanf(FILE *stream, const char *format, ...);
  182. int printf(const char *format, ...);
  183. int scanf(const char *format, ...);
  184. int sprintf(char *s, const char *format, ...);
  185. int sscanf(const char *s, const char *format, ...);
  186. int vfprintf(FILE *stream, const char *format, va_list arg);
  187. int vprintf(const char *format, va_list arg);
  188. int vsprintf(char *s, const char *format, va_list arg);
  189.  
  190.  
  191. /*
  192.  *    Character input/output functions and macros
  193.  */
  194.  
  195. int fgetc(FILE *stream);
  196. char *fgets(char *s, int n, FILE *stream);
  197. int fputc(int c, FILE *stream);
  198. int fputs(const char *s, FILE *stream);
  199. int getc(FILE *stream);
  200. #define getc(p)     (--(p)->_cnt >= 0 ? (int) *(p)->_ptr++ : _filbuf(p))
  201. int getchar(void);
  202. #define getchar()    getc(stdin)
  203. char *gets(char *s);
  204. int putc(int c, FILE *stream);
  205. #define putc(x, p)    (--(p)->_cnt >= 0 ? \
  206.                         ((int) (*(p)->_ptr++ = (unsigned char) (x))) : \
  207.                         _flsbuf((unsigned char) (x), (p)))
  208. int putchar(int c);
  209. #define putchar(x)    putc((x), stdout)
  210. int puts(const char *s);
  211. int ungetc(int c, FILE *stream);
  212.  
  213.  
  214. /*
  215.  *    Direct input/output functions
  216.  */
  217.  
  218. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
  219. size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
  220.  
  221.  
  222. /*
  223.  *    File positioning functions
  224.  */
  225.  
  226. int fgetpos(FILE *stream, fpos_t *pos);
  227. int fseek(FILE *stream, long int offset, int whence);
  228. int fsetpos(FILE *stream, const fpos_t *pos);
  229. long int ftell(FILE *stream);
  230. void rewind(FILE *stream);
  231.  
  232.  
  233. /*
  234.  *    Error-handling functions and macros
  235.  */
  236.  
  237. void clearerr(FILE *stream);
  238. #define clearerr(p) ((void)((p)->_flag &= ~(_IOERR | _IOEOF)))
  239. int feof(FILE *stream);
  240. #define feof(p)     ((p)->_flag & _IOEOF)
  241. int ferror(FILE *stream);
  242. #define ferror(p)    ((p)->_flag & _IOERR)
  243. void perror(const char *s);
  244.  
  245. /*
  246.  * For macros
  247.  */
  248.  
  249. extern FILE _iob[];
  250. #define _NFILE 20
  251. int _filbuf(FILE *);
  252. int _flsbuf(unsigned char, FILE *);
  253.  
  254. /*
  255.  *    Non-ANSI extensions
  256.  *
  257.  * The prefered mechanism for enabling these is by defining __useAppleExts__.  
  258.  * In the absence of this symbol, the __STDC__ symbol is used to enable or
  259.  * disable these extentions.
  260.  */
  261.  
  262. /* CFront can't handle the pretty version of this conditional 
  263. #if defined (__useAppleExts__) || \
  264.     ((defined (applec) && ! defined (__STDC__)) || \
  265.      (defined (__PPCC__) && __STDC__ == 0))
  266. */
  267. #if defined (__useAppleExts__) || ((defined (applec) && ! defined (__STDC__)) || (defined (__PPCC__) && __STDC__ == 0))
  268.  
  269. #define fileno(p)    (p)->_file
  270. FILE *fdopen(int fildes, const char *mode);
  271. void fsetfileinfo (char *filename, unsigned long newcreator, unsigned long newtype);
  272. int getw(FILE *stream);
  273. int putw(int w, FILE *stream);
  274.  
  275. #endif
  276.  
  277. #ifdef __cplusplus
  278. }
  279. #endif
  280.  
  281.  
  282. #endif
  283.